<template>
    <div>
        <el-table
            :data="storeList"
            stripe
            style="width: 100%">
            <el-table-column
            prop="title"
            label="标题"
            width="180">
            </el-table-column>
            <el-table-column
            prop="intro"
            label="简介"
            width="180">
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-button
                    size="mini"
                    @click="handleEdit(scope.row)">编辑</el-button>
                    <el-button
                    size="mini"
                    type="danger"
                    @click="handleDelete(scope.row.id)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
import $api from '../../../api/index'
export default {
    created(){
        this.getStoreList();
    },
    data(){
        return {
            storeList:[]
        }
    },
    methods:{
        getStoreList(){
            $api.getStoreList().then(res => {
                if(res.code === 1){
                    this.storeList = res.data;
                }
            })
        },
        handleEdit(row){
            localStorage.setItem('editStore',JSON.stringify(row));
            this.$router.push('/main/addStore');
        },
        handleDelete(id){
            console.log("id",id)
            $api.destroy(id).then(res => {
                console.log("======",res)
                if(res.code === 1){
                    this.$message({
                        message: '删除成功',
                        type: 'success'
                    });
                    this.getStoreList();
                }
            })
        }
    }
}
</script>